package cn.iocoder.mall.shop.service.service.rpc.service.impl;

import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.utils.common.util.ObjectUtils;
import cn.iocoder.mall.shop.api.ShopClerkRelationShipService;
import cn.iocoder.mall.shop.api.pojo.Shop;
import cn.iocoder.mall.shop.api.pojo.ShopClerkRelationShip;
import cn.iocoder.mall.shop.service.entities.ShopSellerRe;
import cn.iocoder.mall.shop.service.service.IShopClerkRelationShipService;
import cn.iocoder.mall.shop.service.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/***
 *@author yinxucun
 *@date 2019-11-21 18:31 
 */
@Service
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ShopClerkRelationShipService.version}")
public class ShopClerkRelationShipServiceRpcImpl  implements ShopClerkRelationShipService {

    @Autowired
    IShopClerkRelationShipService shopClerkRelationShipService;

    @Autowired
    IShopService shopService;
    /**
     * 给店铺分配店员，，，，，分配之前，先把店员原先和店铺的关系删除
     * @param clerkrId
     * @return
     */
    @Override
    public CommonResult removeById(String clerkrId) {
         shopClerkRelationShipService.deleteAllReaOfClerk(clerkrId);
        return CommonResult.ok();
    }

    @Override
    public CommonResult save(ShopClerkRelationShip temp) {
        return shopClerkRelationShipService.save(ObjectUtils.copyObject(temp, cn.iocoder.mall.shop.service.entities.ShopClerkRelationShip.class))?CommonResult.ok():CommonResult.error("保存失败");
    }

    @Override
    public CommonResult saveBatch(List<ShopClerkRelationShip> list) {
        return shopClerkRelationShipService.saveBatch(ObjectUtils.copyList(list,
                cn.iocoder.mall.shop.service.entities.ShopClerkRelationShip.class))?CommonResult.ok():CommonResult.error("批量保存失败");
    }


    @Override
    public CommonResult sellerIsInShop(String userId,String shopId) {

        cn.iocoder.mall.shop.service.entities.ShopClerkRelationShip db1=shopClerkRelationShipService.getOneByUserIdAndShopId(userId,shopId);
        if (db1==null){
            cn.iocoder.mall.shop.service.entities.ShopClerkRelationShip db2=shopService.getShopSellerShipBySellerIdAndShopId(userId,shopId);
            if (db2==null){
                return CommonResult.error("");
            }
        }


        return CommonResult.ok();

    }

}
